var QualitiyDetails = {//质量管理管理初始化
    id: "QualitiyAssurancesDetailsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

QualitiyDetails.initColumn = function () {//初始化表格的列
    var columns = [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {
            title: '图片类型', field: 'photoType', align: 'center', valign: 'middle', width: 40,
            formatter: function (value, row, index) {
                if (value == "1") {
                    return "术前"
                } else if (value == "2") {
                    return "术中"
                } else if (value == "3") {
                    return "术后"
                } else {
                    return "总分"
                }
            }
        },
        {title: 'A1', field: 'a', align: 'center', valign: 'middle', width: 20},
        {title: 'A2', field: 'b', align: 'center', valign: 'middle', width: 20},
        {title: 'A3', field: 'c', align: 'center', valign: 'middle', width: 20},
        {title: 'A4', field: 'd', align: 'center', valign: 'middle', width: 20},
        {title: 'A5', field: 'e', align: 'center', valign: 'middle', width: 20},
        {title: 'A6', field: 'f', align: 'center', valign: 'middle', width: 20},
        {title: 'A7', field: 'g', align: 'center', valign: 'middle', width: 20},
        {title: '得分', field: 'score', align: 'center', valign: 'middle', width: 20},
        {title: '时间', field: 'createTime', align: 'center', valign: 'middle', width: 50}
    ];
    return columns
};

QualitiyDetails.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        QualitiyDetails.seItem = selected[0];
        return true;
    }
};

QualitiyDetails.search = function () {
    QualitiyDetails.table.refresh({query: QualitiyDetails.formParams()});
};

QualitiyDetails.formParams = function () {//查询质量管理列表
    var queryData = {};
    queryData['startUploadTime'] = $("#startUploadTime").val();
    queryData['endUploadTime'] = $("#endUploadTime").val();
    queryData['addName'] = $("#addName").val();
    queryData['arrivalStore'] = $("#arrivalStore").val();
    queryData['status'] = $("#status").val();
    return queryData;
};

QualitiyDetails.close = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
};

QualitiyDetails.additionalData = function () {
    var aValue = 0, bValue = 0, cValue = 0;
    var data = $('#QualitiyAssurancesDetailsTable').bootstrapTable('getData', true);
    for (var i = 0; i < data.length; i++) {
        aValue += parseFloat(data[i].a);
        bValue += parseFloat(data[i].b);
        cValue += parseFloat(data[i].c);
    }
    var a = (aValue / 3).toFixed(2),
        b = (bValue / 3).toFixed(2),
        c = (cValue / 3).toFixed(2),
        d = parseFloat(data[1].d).toFixed(2),
        e = parseFloat(data[2].e).toFixed(2),
        f = parseFloat(data[2].f).toFixed(2),
        g = parseFloat(data[2].g).toFixed(2);
    var score = parseFloat(a) + parseFloat(b) + parseFloat(c) + parseFloat(d) + parseFloat(e) + parseFloat(f) + parseFloat(g);
    var arr = [{
        id: '',
        photoType: '0',
        a: a,
        b: b,
        c: c,
        d: d,
        e: e,
        f: f,
        g: g,
        score: score.toFixed(2),
        createTime: ''
    }];
    $('#QualitiyAssurancesDetailsTable').bootstrapTable('append', arr);
};

$(function () {
    var num = $("#numValue").val();
    var defaultColunms = QualitiyDetails.initColumn();
    var table = new BSTable(QualitiyDetails.id, "/doctorLooked/getIntelligentScoreDetailsList/" + num, defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(QualitiyDetails.formParams());
    QualitiyDetails.table = table.init();
    $('#QualitiyAssurancesDetailsTable').bootstrapTable('resetView', {height: $(window).height() - 210});
    $(document).on("load-success.bs.table", function () {
        QualitiyDetails.additionalData();
    })
});